package com.qf.controller;

import com.qf.pojo.Permission;
import com.qf.pojo.Role;
import com.qf.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：冯国清
 * 项目名：com.qf.controller
 * 时间：2020/8/19 21:13
 * 描述:
 */
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("/findRoleByrid/{rid}")
    public Role findRoleByrid(@PathVariable("rid")Integer rid){
        return roleService.findRoleByrid(rid);
    }
    @RequestMapping("/findAllRole")
    public List<Role> getAllRole(){
        return roleService.getAllRole();
    }

    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    public int addPermission(@RequestBody Role role){
        int add = roleService.add(role);
        if (add>0){
            return 1;
        }else {
            return 0;
        }
    }
    @RequestMapping(value = "/updateRole",method = RequestMethod.POST)
    public int updateBooks(@RequestBody Role role){
        int update = roleService.update(role);
        if (update>0){
            return 1;
        }else {
            return 0;
        }
    }

    @RequestMapping("/deleteRole/{rid}")
    public int deletePermission(@PathVariable("rid")int rid) {
        int delete = roleService.delete(rid);
        if (delete>0){
            return 1;
        }else {
            return 0;
        }
    }
}
